Tuesday, July 31, 2007

First bits of PyQt

Yesterday I wrote my first PyQt application. It is really simple program, called "tray", which lives in system tray and notifies user of new messages at my favorite social network Vkontakte.ru (Russian clone of FaceBook.com).
The program is less than 170 lines of code. You can try it if you are registered at vkontakte.ru, but the program doesn't matter now.
I am very pleased with simplicity of creation of portable rich GUI applications with PyQt, but as always there are some issues on Windows. I created the program on my favorite old Linux box with vim, so there I had no problems with PyQt4 installation and no need of packaging, because the program consists of one file and three icons.
Then I decided to try it on Windows. First of all I installed newest PyQt 4.3.0. This new version is now packed in self-installing archive, which includes Qt and Eric4 IDE, so now you shouldn't have problems which I described in this post.
After that the program worked perfectly, but I needed to create standalone version for people who don't have Python and PyQt on their PCs.
This is rather simple task, but I've spent several hours fighting some issues.
I used py2exe to create standalone executable. The problem was to include PyQt into it. The idea is simple: I needed to specify that PyQt should be included. So I used solution from py2exe.org. I created file called setup.py with following contents:

from distutils.core import setup
import py2exe
setup(windows=[{"script":"tray.py"}], options={"py2exe":{"includes":["sip"]}})

Then I ran python setup.py install py2exe.
But I received errors like "module import failed: _qt". So I decided to mention inclusion explicitly: python setup.py install py2exe --includes=PyQt4,sip. It didn't help, but error message changed to "cannot find QApplication". Then I tried to reorganize imports in my code:

import sys
from PyQt4.Qt import *
from PyQt4 import QtCore, QtGui

gave correct result, and the executable was created.
I believe that this problem with imports is temporary and will be fixed in near future.

So then I used Inno Setup to create setup package and it was really easy.

Conclusion
It is really easy to create portable applications with great GUI with PyQt4.
The only trade off is the size of installed application on Windows: for my 170 lines of code project I've got 5 Mb setup package, which extracts into 17 Mb application.
The reason is simple - lack of common packaging system with dependencies on Windows, so the program needs it's own copy of Python and PyQt.

Labels: , , , , , ,

Monday, June 4, 2007

Eric IDE on Unfriendly System

At morning I've read on linux.org.ru of new version of Eric IDE. After looking at screenshots I was very interested in this IDE.

So I decided to install it on my work PC.
Unfortunately it's running Windows XP, and I can't change it. And those OS doesn't have normal package manager.

To install Eric I needed Qt, Python, PyQt, QScintilla.

I had opensource Qt (installed with MinGW) and Active Python installed on my PC.
So I downloaded PyQt, QScintilla and Eric.
I installed binary package of PyQt and started to build QScintilla with MinGW. The build was successful, but python bindings didn't installed because of some error with SIP. So I tried to build SIP separately. It wasn't build because of some unknown linking errors with Python libraries.
I searched trough the internet, but was unable to find solution.
So I decided to reinstall everything.

First of all, I downloaded Python from python.org and installed it (it was what really helped).
Then I reinstalled Qt.
Then I downloaded source package of PyQt, unpacked it and run

python configure.py

make

make install

The build completed with no errors.
Next I downloaded QScintilla source and unpacked it. Then I went to Qt4 subdirectory, and run

qmake qscintilla.pro

make

make install

After that I went to Python subfolder of QScintilla source, and ran

python configure.py

make

make install

When the build was completed I had all needed to run Eric4.
(Also SIP is included into PyQt, so one don't need to build it separately).
Then I unpacked Eric and run
python install.py
eric4.bat

It started after all!

Eric is really great, but I've met the problem on second run - it haven't started because of some error in debugger configuration. So I had to turn remote debugging and passive debugging on through eric-configure.bat. After it the IDE started normally.

Labels: , , , , , ,